<template>
  <div class="login-container" :class="themeClass">
    <div class="login-box">
      <div class="login-header">
        <h1>{{ themeConfig.title }}</h1>
        <p>{{ themeConfig.subtitle }}</p>
      </div>
      
      <form class="login-form" @submit.prevent="handleLogin">
        <div class="form-group">
          <label for="username">用户名</label>
          <input 
            type="text" 
            id="username" 
            v-model="formData.username" 
            :placeholder="themeConfig.usernamePlaceholder"
            required
          />
        </div>
        
        <div class="form-group">
          <label for="password">密码</label>
          <input 
            type="password" 
            id="password" 
            v-model="formData.password" 
            :placeholder="themeConfig.passwordPlaceholder"
            required
          />
        </div>
        
        <div class="form-group checkbox-group">
          <label>
            <input type="checkbox" v-model="formData.rememberMe" />
            <span>记住我</span>
          </label>
        </div>
        
        <button type="submit" class="login-btn">
          {{ themeConfig.loginButtonText }}
        </button>
      </form>
      
      <div class="login-footer">
        <a href="#" class="forgot-password">{{ themeConfig.forgotPasswordText }}</a>
        <p class="current-domain">当前域名: {{ currentDomain }}</p>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'LoginPage',
  data() {
    return {
      formData: {
        username: '',
        password: '',
        rememberMe: false
      },
      currentDomain: '',
      themeConfig: {}
    }
  },
  computed: {
    themeClass() {
      return this.isDomainA ? 'theme-a' : 'theme-b'
    },
    isDomainA() {
      // 判断是否为A域名（例如：example-a.com, localhost:3000等）
      return this.currentDomain.includes('a') || 
             this.currentDomain.includes('localhost') ||
             this.currentDomain.includes('127.0.0.1')
    }
  },
  mounted() {
    this.getCurrentDomain()
    this.setThemeConfig()
  },
  methods: {
    getCurrentDomain() {
      this.currentDomain = window.location.hostname
      console.log('当前域名:', this.currentDomain)
    },
    setThemeConfig() {
      if (this.isDomainA) {
        // A样式配置
        this.themeConfig = {
          title: '欢迎登录 - 系统A',
          subtitle: '请使用您的账户信息登录',
          usernamePlaceholder: '请输入用户名',
          passwordPlaceholder: '请输入密码',
          loginButtonText: '登录系统A',
          forgotPasswordText: '忘记密码？'
        }
      } else {
        // B样式配置
        this.themeConfig = {
          title: '系统B登录',
          subtitle: '请输入您的登录凭据',
          usernamePlaceholder: '用户名',
          passwordPlaceholder: '密码',
          loginButtonText: '登录系统B',
          forgotPasswordText: '忘记密码'
        }
      }
    },
    handleLogin() {
      console.log('登录信息:', this.formData)
      console.log('当前主题:', this.isDomainA ? 'A' : 'B')
      // 这里可以添加实际的登录逻辑
      alert(`登录请求已发送，当前使用${this.isDomainA ? 'A' : 'B'}样式`)
    }
  }
}
</script>

<style scoped>
.login-container {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Arial', sans-serif;
  transition: all 0.3s ease;
}

.login-box {
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
  padding: 40px;
  width: 100%;
  max-width: 400px;
  transition: all 0.3s ease;
}

.login-header {
  text-align: center;
  margin-bottom: 30px;
}

.login-header h1 {
  margin: 0 0 10px 0;
  font-size: 28px;
  font-weight: 600;
}

.login-header p {
  margin: 0;
  color: #666;
  font-size: 14px;
}

.login-form {
  margin-bottom: 20px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  font-size: 14px;
}

.form-group input[type="text"],
.form-group input[type="password"] {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid #e1e5e9;
  border-radius: 8px;
  font-size: 16px;
  transition: border-color 0.3s ease;
  box-sizing: border-box;
}

.form-group input:focus {
  outline: none;
  border-color: #007bff;
}

.checkbox-group {
  display: flex;
  align-items: center;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  margin-bottom: 0;
  cursor: pointer;
}

.checkbox-group input[type="checkbox"] {
  margin-right: 8px;
  width: auto;
}

.login-btn {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.login-footer {
  text-align: center;
  margin-top: 20px;
}

.forgot-password {
  color: #007bff;
  text-decoration: none;
  font-size: 14px;
}

.forgot-password:hover {
  text-decoration: underline;
}

.current-domain {
  margin-top: 10px;
  font-size: 12px;
  color: #999;
}

/* A样式主题 */
.theme-a {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.theme-a .login-box {
  border: 2px solid #667eea;
}

.theme-a .login-header h1 {
  color: #667eea;
}

.theme-a .login-btn {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.theme-a .login-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.theme-a .forgot-password {
  color: #667eea;
}

/* B样式主题 */
.theme-b {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.theme-b .login-box {
  border: 2px solid #f093fb;
}

.theme-b .login-header h1 {
  color: #f5576c;
}

.theme-b .login-btn {
  background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
  color: white;
}

.theme-b .login-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(240, 147, 251, 0.4);
}

.theme-b .forgot-password {
  color: #f5576c;
}

/* 响应式设计 */
@media (max-width: 480px) {
  .login-box {
    margin: 20px;
    padding: 30px 20px;
  }
  
  .login-header h1 {
    font-size: 24px;
  }
}
</style> 